package com.example.blog.util;

import com.example.blog.pojo.blog;
import com.example.blog.service.blogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class footerUtile {

    @Autowired
    com.example.blog.service.blogService blogService;

    /**
     * 获取所有blog，倒序排列然后移除list到大小只有3
     * @return
     */
    public List<blog> footBlog(){
        List<blog> blogs = blogService.listBlog();
        Collections.reverse(blogs);
        if (blogs.size() > 3){
            for (int i = blogs.size()-1; i > 2 ; i--) {
                blogs.remove(i);
            }
        }
        return blogs;
    }
}
